a t e v a n s . c o m

(╯°□°)╯︵ <ǝlqɐʇ/>

du -skh *

Well, that was simple, right?

 

Unobtrusive Ruby is any Ruby code that stays out of your way. It does not make you write lots of boilerplate, or stub methods, or open classes. It is decoupled. Its tests run quickly, its classes fit on one screen, its methods are tiny, and it is quickly refactorable.

Good design goals

  • - (Object) select_all(sql, name = nil)

    Returns an array of record hashes with the column names as keys and column values as values.

  • - (Object) select_one(sql, name = nil)

    Returns a record hash with the column names as keys and column values as values.

  • - (Object) select_rows(sql, name = nil)

    Returns an array of arrays containing the field values.

  • - (Object) select_value(sql, name = nil)

    Returns a single value from a record.

  • - (Object) select_values(sql, name = nil)

    Returns an array of the values of the first column in a select:.

  • Good stuff if you're feeling like a SQL wizard

    A Collection of Useful .gitignore Templates

    That's what we're trying to build. Please contribute by forking and sending a pull request.

    Also please only modify one file per commit. This'll make merging easier for everyone.

    Global gitignores (OS-specific, editor-specific) should go into the Global/ directory.

    For more information on gitignore: gitignore(5)

    Global Ignores

    git has a global configuration that applies rules to all of your projects. For example:

    git config --global core.excludesfile ~/.global_ignore

    ... will apply the rules in ~/.global_ignore for all of your repos.

    This is useful if you use an editor (like Emacs) that drops backup files, or if you work in an environment that generates binary or intermediate files that are always ignored.

    Nifty!

    Common MySQL Queries

    Good overview to show you the easy way, the better way, and the clever way to do a whole bunch of typical queries. Good way to learn a little optimization for SQL.

    I ran into this crap when I needed to purge a massive number of records from a database. All you need to do is edit the timeout setting in your MySQL config file.

    On my Mac it is located at : /etc/my.cnf

    Uncomment the line:

    innodb_lock_wait_timeout = 50

    And change the setting to 500 (its seconds)

    Restart mysql and rerun your query.


    sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysqld.plist
    sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist

    If you make this change on a production server you may want to set it back to the default setting. I don’t know what the consequences of a long timeout setting would be.

    If you're running the Homebrew mysql package, you might have to create `/etc/my.cnf` -- there are a few examples in `/usr/local/Cellar/mysql/5.1.53/share/mysql` but I don't think they're used until you copy one to `/etc/my.cnf`

    If your function only requires one variable from an object passed into it, require that variable and not the whole object. Example:

    def delete_cache_key(user)
      cache.delete(user.username)
      cache.delete("all_users_" + user.username)
      cache.delete("special_users_" + user.username)
    end

    NO! WRONG! Better:

    def delete_cache_key(username)
      cache.delete(username)
      cache.delete("all_users_" + username)
      cache.delete("special_users_" + username)
    end

    /rant

    >> Cantaloupe.new.days rescue 5
    => 5

    See? A cantaloupe has five days. Don't worry about it. It's fine.

    You could even ask the Cantaloupe to find_by_email. Why worry about which model it will find? You'll find something by email; that's for sure!

    This is awesome. Has anyone written a JS implementation of this yet?

    It's because arrays in Ruby are mutable, so your default array object is getting added to each time with <<. The object_id's of your docs will be different, but the object_id's of the arrays will be the same.

    Damn. Makes sense, I guess. Thanks, Plastic Chicken!

    Snippet is a jQuery syntax highlighting plugin built on top of the SHJS script found on SourceForge. Snippet provides a quick and easy way of highlighting source code passages in HTML documents.

    Baller. In use now on http://stdout.heyzap.com

    Mastodon